/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufba.lasid.v1.jitclouds.mda.cloud;

import br.ufba.lasid.v1.jitclouds.mda.MDA.Contexts;
import br.ufba.lasid.v1.jitclouds.mda.api.JiTFTPlannerAPI;
import br.ufba.lasid.v1.jitclouds.mda.datatypes.BasicCluster;
import br.ufba.lasid.v1.jitclouds.mda.datatypes.FTServiceLevel;
import br.ufba.lasid.v1.jitclouds.mda.datatypes.plan.Plan;
import br.ufba.lasid.v1.jitclouds.mda.datatypes.report.Report;
import br.ufba.lasid.v1.utils.ReadFileForAssessment;
import java.io.IOException;
import java.util.List;

/**
 *
 * @author aliriosa
 */
public class JiTFTPlanner implements JiTFTPlannerAPI{

    static int choosed=0;
    
    public Plan plan(String resourceid, FTServiceLevel ftsLevel, Report cContextInfo) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public Plan plan(String resourceid, FTServiceLevel ftsLevel, Plan inPlan, Contexts context) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
    

    public Plan update(Plan oldReplicationPlan, Plan newRecoveryPlan) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
    //circle basic strategy
    public Report BasicPlan(FTServiceLevel ftsLevel) throws IOException{
        Report r = new Report();
        List<BasicCluster> clusterList = ftsLevel.get("ClusterList");
        String MDA_HOME = System.getenv("MDA_HOME");           
        Runtime.getRuntime().exec(MDA_HOME + "att-azones.sh");      
        ReadFileForAssessment availability = new ReadFileForAssessment(MDA_HOME + "azones.txt");
        
        List<BasicCluster> bCluster = availability.getClusterList();
        
        BasicCluster cluster = null;
        
        Boolean b = false;
        while(!b) {
            choosed %= clusterList.size();
            for(BasicCluster bC : clusterList) {
                if( bCluster.get(choosed).getAddress().equals(bC.getAddress()) ) {
                    b = true;
                    break;
                }
            }
            choosed++;
        }
        
        r.set("theCluster", bCluster.get(choosed));
        return r;
    } 
      
}
